import random
import string

import pymysql
"""
db_phy = {
    'host': 'im-stage.ct0seoua2344.ap-east-1.rds.amazonaws.com',  # 测试
    'user': 'admin',  # 用户名
    'password': 'dtAIlpmcBbkcdmi7gppk',  # 密码
    'port': 3306,  # 端口
    'database': 'im_user'  # 数据库名
}
"""

db_phy = {
    'host': 'new-im-server.ct0seoua2344.ap-east-1.rds.amazonaws.com',  # 生产
    'user': 'temporary',  # 用户名
    'password': 'xPQZYyO56ztIsxlKUkbWY5mgd',  # 密码
    'port': 3306,  # 端口
    'database': 'im_user'  # 数据库名
}
# 从usb读取数据
def read_from():
    conn = pymysql.connect(**db_phy)
    cursor = conn.cursor()
    # 生成号码列表
    numbers = [f"ouya{str(i).zfill(4)}" for i in range(2, 51)]#51
    # 输出结果
    for number in numbers:
        # 插入数据并处理
        try:
            # 插入数据库的 SQL 语句
            invite_code = ''.join(random.choices(string.ascii_uppercase + string.digits, k=6))
            cursor.execute('INSERT INTO `user` (app_version, nick_name, `identify`, invite_code, gender, plat, status, privacy, create_time, update_time) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, NOW(), NOW())',
                           (306, number, number, invite_code, 0, 0, 1, 4144))
            new_id = cursor.lastrowid  # 获取新增的 ID

            cursor.execute(
                'INSERT INTO `account` (account, account_type, status, `uid`, password, is_login_out, create_time) VALUES (%s, %s, %s, %s, %s, %s, NOW())',
                ("", 1, 1, new_id, "559453ae653dd2175ba800bc4f99e8ab", 1))
            print(f"new_id: {new_id}")
            conn.commit()  # 提交更改

        except Exception as e:
            print(f"异常信息: {e}")
            break  # 停止程序

    # 关闭数据库连接
    cursor.close()
    conn.close()


if __name__ == "__main__":
    read_from()